'use strict';

/**
 * @name metalabPartnerApp
 * @description
 * # 迈科技游客系统
 *
 * Main module of the application.
 * 项目的入口，依赖项
 *
 */

angular
    .module('metalabPartnerApp', [
        'ngAnimate',
        'ngCookies',
        'ngMessages',
        'ngResource',
        'ngRoute',
        'ngSanitize',
        'ngTouch',
        'ui.router',
        'ui.bootstrap',
        'monospaced.qrcode',
        'toaster',
        'meta.qnuploader',
        'froala',
        'ui.select',
        'angular-spinkit',
        'cgBusy'
    ]).config(['$locationProvider', function ($locationProvider) {
        $locationProvider.html5Mode(CONFIG.html5Mode);
    }])
    .value('cgBusyDefaults', {
        message: '加载中...',
        templateUrl: 'views/common/angular-busy.html',
        minDuration: 400
    })
    .run(['$rootScope', '$state', 'Passport', 'Officer', '$uibModalStack', '$http', '$window', '$q', 'MetaResources', 'MetaUtils',
        function ($rootScope, $state, Passport, Officer, $uibModalStack, $http, $window, $q, MetaResources, MetaUtils) {

            $rootScope.$state = $state;

            $http.defaults.headers.common['x-field-style'] = 'camelcase';

            $rootScope.CONFIG = CONFIG;

            //权限初始设置
            Passport.registry();
            Passport.init();

            $rootScope.previousState = {};

            $rootScope.$on('$stateChangeStart', function (event, toState) {
                //清除所有的模态框
                $uibModalStack.dismissAll();
            });

            $rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) {
                //处理如果url中有officer参数
                Officer.check(toParams);

                $rootScope.previousState.state = fromState;
                $rootScope.previousState.params = fromParams;

                MetaUtils.statistic();
            });


            $rootScope.openOfficerVerifyModal = function () {
                return Officer.openVerifyModal();
            };

            $rootScope.clearOfficerVerifyModal = function () {
                Officer.clearModal();
            };

            $rootScope.isSignIn = function () {
                return Passport.isSignIn();
            };

            $rootScope.signOut = function () {
                Passport.signOut();
            };

        }
    ])
;

